package com.yqyd.web.controller.hy.app;

import com.yqyd.common.annotation.Anonymous;
import com.yqyd.common.core.domain.R;
import com.yqyd.hy.domain.HyCategory;
import com.yqyd.hy.domain.HyGoods;
import com.yqyd.hy.dto.GoodsSearchDto;
import com.yqyd.hy.service.IHyCategoryService;
import com.yqyd.hy.service.IHyGoodsService;
import com.yqyd.system.domain.SysConfig;
import com.yqyd.system.service.ISysConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分类
 */
@RestController
@RequestMapping("/api/app/config")
@CrossOrigin
public class ApiConfigController {

    private static final String INDEX_SHOW = "hy.index.show";
    private static final String CHAT_IMG_KEY = "hy.chat.img";
    private static final Long  CHAT_IMG_KEY_ID = 100L;

    @Resource
    private ISysConfigService configService;

    @GetMapping("/IndexShow")
    @Anonymous
    public R<String> IndexShow() {
        return R.ok(configService.selectConfigByKey(INDEX_SHOW));
    }


    @GetMapping("/ChatImg")
    @Anonymous
    public R<String> ChatImg() {
        return R.ok(configService.selectConfigByKey(CHAT_IMG_KEY));
    }

    @PutMapping("/UpdateImg")
    public R<String> UpdateImg(@RequestParam String imgUrl) {
        SysConfig config = new SysConfig();
        config.setConfigId(CHAT_IMG_KEY_ID);
        config.setConfigValue(imgUrl);
        configService.updateConfig(config);
        return R.ok();
    }


}
